package com.zmn.plat.services.impl.channel.mark;

import com.zmn.common.utils.date.DateUtil;

import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.plat.model.entity.channel.mark.ChannelMark;
import com.zmn.plat.model.entity.channel.mark.ChannelMarkQuery;
import com.zmn.plat.persistence.interfaces.channel.mark.ChannelMarkDao;
import com.zmn.plat.services.interfaces.channel.mark.ChannelMarkService;
import org.springframework.util.CollectionUtils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import com.zmn.common.constant.GlobalConsts;

/**
 * 描述: 渠道标示接口实现类
 *
 * @author jiafei
 * @since  2021/12/06 11:23
 */
@Slf4j
@Service
public class ChannelMarkServiceImpl implements ChannelMarkService {

    private static final String TAG = "渠道标示基础服务接口";

    @Resource
    private ChannelMarkDao channelMarkDao;

    @Override
    public ChannelMark findById(Integer markId) {

        if (Objects.isNull(markId)) {
            log.error("[{}],根据id查询数据markId为null", TAG);
            return null;
        }
        return channelMarkDao.findById(markId);
    }

    @Override
    public List<ChannelMark> listByIds(List<Integer> markIds) {

        if (CollectionUtils.isEmpty(markIds)) {
            log.error("[{}],按条件查询数据,markIds为null", TAG);
            return Collections.emptyList();
        }
        return channelMarkDao.listByIds(markIds);
    }

    @Override
    public List<ChannelMark> listByQuery(ChannelMarkQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        return channelMarkDao.listByQuery(query);
    }

    @Override
    public List<ChannelMark> listPageByQuery(ChannelMarkQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return Collections.emptyList();
        }
        query.setTotalCount(channelMarkDao.countPageByQuery(query));
        return channelMarkDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(ChannelMarkQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return channelMarkDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ChannelMark channelMark) {

        if (Objects.isNull(channelMark.getMarkId())){
            log.error("[{}],根据id修改数据,channelMark为null", TAG);
            return null;
        }
        return channelMarkDao.updateByKey(channelMark);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, LoginStaff operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        channelMarkDao.updateStatusBatch(ids, status, operator.getDeptName() + "-" + operator.getRealName(), DateUtil.getNow());
    }

    @Override
    public Integer insert(ChannelMark channelMark){

        if (Objects.isNull(channelMark)){
            log.error("[{}],新增数据,channelMark为null", TAG);
            return null;
        }
        return channelMarkDao.insert(channelMark);
    }

    @Override
    public void insertBatch(List<ChannelMark> list){

        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        channelMarkDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer markId) {

        if (Objects.isNull(markId)){
            log.error("[{}],根据id删除数据,markId为null", TAG);
            return null;
        }
        return channelMarkDao.deleteByKey(markId);
    }

}